//
//  CTPersonalGenderModifyView.m
//  ConstellationTalk_0.1
//
//  Created by riley on 15/6/29.
//  Copyright (c) 2015年 riley chu. All rights reserved.
//

#import "CTPersonalGenderModifyView.h"
#import "CTDebugManager.h"
#import "CTHeader.h"
#import "CTAppLanguage.h"
#import "UIViewAdditions.h"
#import "CTTextManager.h"

@interface CTPersonalGenderModifyView()
{
    UIView      *topView;
    UIButton    *manBtn;
    UIButton    *womanBtn;
    
    NSString    *genderStr;
}

@end

@implementation CTPersonalGenderModifyView

@synthesize delegate;

- (void)dealloc
{
    delegate = nil;
    [topView removeFromSuperview];
    topView = nil;
    genderStr = nil;
    [manBtn removeFromSuperview];
    manBtn = nil;
    [womanBtn removeFromSuperview];
    womanBtn  = nil;

    [CTDebugManager showDebugLogInfo:@"dealloc : CTSetView Is Removed!!!"];
}

- (instancetype)init
{
    self = [super init];
    if (self)
    {
        self.frame = CGRectMake(0, 0,CT_HEADER_SCREEN_WIDTH,CT_HEADER_SCREEN_HEIGHT);
        self.backgroundColor = CT_HEADER_WHITE_COLOR;
        [self createSetTitleView];
        [self personalGenderModifView];
    }
    return self;
}
//创建标题
- (void)createSetTitleView
{
    topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, CT_HEADER_SCREEN_WIDTH, 64)];
    topView.backgroundColor = CT_HEADER_WHITE_COLOR;
    topView.alpha =0.98;
    [self addSubview:topView];
    
    //标题
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 20, CT_HEADER_SCREEN_WIDTH, 44)];
    titleLabel.text = [CTAppLanguage localizedStringForKey:@"personalSignGenderView_title_text" withValue:nil withTable:@"Language"];
    titleLabel.font = [UIFont systemFontOfSize:19.0f];
    titleLabel.textColor = CT_HEADER_GREEN_COLOR;
    
    titleLabel.textAlignment = NSTextAlignmentCenter;
    [topView addSubview:titleLabel];
    
    //返回按钮
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    backButton.frame = CGRectMake(0, 20, 44, 44);
    [backButton addTarget:self action:@selector(backButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [backButton setImage:[UIImage imageNamed:CT_HEADER_BACK_IMAGE] forState:UIControlStateNormal];
    [backButton setImage:[UIImage imageNamed:CT_HEADER_BACK_IMAGE_CLICK] forState:UIControlStateHighlighted];
    [topView addSubview:backButton];
    
    UIButton *finishButton = [UIButton buttonWithType:UIButtonTypeCustom];
    finishButton.frame = CGRectMake(CT_HEADER_SCREEN_WIDTH-44,20 , 44, 44);
    [finishButton addTarget:self action:@selector(finishButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [finishButton setTitle:[CTAppLanguage localizedStringForKey:@"userNickNameView_saveLabel_text" withValue:nil withTable:@"Language"] forState:UIControlStateNormal];
    finishButton.titleLabel.font = [UIFont systemFontOfSize:15.0f];
    [finishButton setTitleColor:CT_HEADER_GREEN_COLOR forState:UIControlStateNormal];
    [finishButton setTitleColor:CT_HEADER_GREEN_COLOR forState:UIControlStateHighlighted];
    [topView addSubview:finishButton];
    
    UILabel * topBottomLine = [[UILabel alloc]initWithFrame:CGRectMake(0, topView.height-0.5, CT_HEADER_SCREEN_WIDTH, 0.5)];
    topBottomLine.backgroundColor = CT_HEADER_DEEPLINE_COLOR;
    [topView addSubview:topBottomLine];
}

- (void)personalGenderModifView
{
    UILabel * viewTopLine = [[UILabel alloc]initWithFrame:CGRectMake(0, topView.bottom+20, CT_HEADER_SCREEN_WIDTH, 0.5)];
    viewTopLine.backgroundColor = CT_HEADER_BRIGHTLINE_COLOR;
    [self addSubview:viewTopLine];
    
    UILabel *sexLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, viewTopLine.bottom, 80, 50)];
    sexLabel.font = [UIFont fontWithName:nil size:18];
    sexLabel.text = [CTAppLanguage localizedStringForKey:@"registerView_sex_label_text" withValue:nil withTable:@"Language"];
    sexLabel.textColor = CT_HEADER_BLACK_COLOR;
    sexLabel.textAlignment = NSTextAlignmentLeft;
    [self addSubview:sexLabel];
    
    manBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    manBtn.frame = CGRectMake((CT_HEADER_SCREEN_WIDTH/2)-67, sexLabel.origin.y, 67, sexLabel.height);
    [manBtn addTarget:self action:@selector(sexBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    manBtn.tag = 1000;
    manBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    [manBtn setTitle:[CTAppLanguage localizedStringForKey:@"registerView_sex_btn_man" withValue:nil withTable:@"Language"] forState:UIControlStateNormal];
    [manBtn setTitleColor:CT_HEADER_GREEN_COLOR forState:UIControlStateNormal];
    [self addSubview:manBtn];
    
    womanBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [womanBtn setTitle:[CTAppLanguage localizedStringForKey:@"registerView_sex_btn_woman" withValue:nil withTable:@"Language"] forState:UIControlStateNormal];
    [womanBtn addTarget:self action:@selector(sexBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    womanBtn.tag = 1001;
    womanBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    womanBtn.frame = CGRectMake((CT_HEADER_SCREEN_WIDTH/2), sexLabel.origin.y, 67, sexLabel.height);
    [womanBtn setTitleColor:CT_HEADER_DEEPLINE_COLOR forState:UIControlStateNormal];
    [self addSubview:womanBtn];
    
    UILabel * viewBottomLine = [[UILabel alloc]initWithFrame:CGRectMake(0, sexLabel.bottom, CT_HEADER_SCREEN_WIDTH, 0.5)];
    viewBottomLine.backgroundColor = CT_HEADER_BRIGHTLINE_COLOR;
    [self addSubview:viewBottomLine];
    
    
    
}

#pragma mark titleView_Action
- (void)backButtonAction:(UIButton *)sender
{
    if ([self.delegate respondsToSelector:@selector(personalGenderModifyViewSelectedBackBtnAction:)])
    {
        [self.delegate personalGenderModifyViewSelectedBackBtnAction:self];
    }
}
- (void)finishButtonAction:(UIButton *)sender
{
    NSString * sex_str = genderStr;
    
    if ([[CTTextManager shareInstance] isBlankString:sex_str] == YES || [sex_str isEqualToString:@"0"]) {
        sex_str = @"0";
    }else if ([genderStr isEqualToString:@"1"])
    {
        sex_str = @"1";
    }else{
        sex_str = @"2";
    }
    
    if ([self.delegate respondsToSelector:@selector(personalGenderModifyViewSelectedSaveBtnAction: withSexString:)])
    {
        [self.delegate personalGenderModifyViewSelectedSaveBtnAction:self withSexString:sex_str];
    }
}
#pragma mark mainView_Action
- (void)sexBtnAction:(UIButton *)sender
{
    if (sender.tag ==1000)
    {
        [manBtn setTitle:[CTAppLanguage localizedStringForKey:@"registerView_sex_btn_man" withValue:nil withTable:@"Language"] forState:UIControlStateNormal];
        [manBtn setTitleColor:CT_HEADER_GREEN_COLOR forState:UIControlStateNormal];
        
        [womanBtn setTitle:[CTAppLanguage localizedStringForKey:@"registerView_sex_btn_woman" withValue:nil withTable:@"Language"] forState:UIControlStateNormal];
        [womanBtn setTitleColor:CT_HEADER_DEEPLINE_COLOR forState:UIControlStateNormal];
        genderStr = @"1";
    }
    else
    {
        [manBtn setTitle:[CTAppLanguage localizedStringForKey:@"registerView_sex_btn_man" withValue:nil withTable:@"Language"] forState:UIControlStateNormal];
        [manBtn setTitleColor:CT_HEADER_DEEPLINE_COLOR forState:UIControlStateNormal];
        
        [womanBtn setTitle:[CTAppLanguage localizedStringForKey:@"registerView_sex_btn_woman" withValue:nil withTable:@"Language"] forState:UIControlStateNormal];
        [womanBtn setTitleColor:CT_HEADER_GREEN_COLOR forState:UIControlStateNormal];
        genderStr = @"2";
    }
}

#pragma mark -setter-
- (void)setSexWithStr:(NSString *)sexStr
{
    genderStr = sexStr;
    if ([[CTTextManager shareInstance] isBlankString:sexStr] == YES || [sexStr isEqualToString:@"0"]) {
        
        [manBtn setTitleColor:CT_HEADER_DEEPLINE_COLOR forState:UIControlStateNormal];
        [womanBtn setTitleColor:CT_HEADER_DEEPLINE_COLOR forState:UIControlStateNormal];
        
        return;
    }
    
    if ([sexStr isEqualToString:@"1"]) {
        //男
        [manBtn setTitle:[CTAppLanguage localizedStringForKey:@"registerView_sex_btn_man" withValue:nil withTable:@"Language"] forState:UIControlStateNormal];
        [manBtn setTitleColor:CT_HEADER_GREEN_COLOR forState:UIControlStateNormal];
        
        [womanBtn setTitle:[CTAppLanguage localizedStringForKey:@"registerView_sex_btn_woman" withValue:nil withTable:@"Language"] forState:UIControlStateNormal];
        [womanBtn setTitleColor:CT_HEADER_DEEPLINE_COLOR forState:UIControlStateNormal];
    }else{
        //女
        [manBtn setTitle:[CTAppLanguage localizedStringForKey:@"registerView_sex_btn_man" withValue:nil withTable:@"Language"] forState:UIControlStateNormal];
        [manBtn setTitleColor:CT_HEADER_DEEPLINE_COLOR forState:UIControlStateNormal];
        
        [womanBtn setTitle:[CTAppLanguage localizedStringForKey:@"registerView_sex_btn_woman" withValue:nil withTable:@"Language"] forState:UIControlStateNormal];
        [womanBtn setTitleColor:CT_HEADER_GREEN_COLOR forState:UIControlStateNormal];
    }
    
 
}
@end
